//
//  DynamicViewController.m
//  SelfDriving
//
//  Created by apple on 16/1/28.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "DynamicViewController.h"
#import "BusinessService+FJ.h"
#import "zanCell.h"
#import "KYExpressionInputView.h"
#import "EmojiTextAttachment.h"
#import "FJModel.h"
#import "SDCycleScrollView.h"
#import "KPDViewController.h"

@interface DynamicViewController ()<UITableViewDataSource,UITableViewDelegate,BaseTableDetelage,UICollectionViewDelegate,UICollectionViewDataSource,UITextViewDelegate,KYExpressionInputViewDelegate,SDCycleScrollViewDelegate,UIActionSheetDelegate,MLEmojiLabelDelegate>
@property (weak, nonatomic) IBOutlet BaseTable *table;
@property (strong, nonatomic) UITextView *hfText;
@property (strong, nonatomic) UIView *inputView;
@property (strong, nonatomic) UIButton *bqBtn;
@property (weak, nonatomic) IBOutlet UIView *adView;
@property (strong, nonatomic) UIButton *senderBtn;

@end

@implementation DynamicViewController
{
    NSMutableArray<DTModel *> *data;
    UILabel *notlabel;
    int cont;
    LoginResponseModel *user;
    LoginResponseModel *models;
    TCNotify *not;
    
    KYExpressionInputView *inputView;
    BOOL isUp;
    int isReplySingle;//是否回复单人
    NSMutableDictionary *ReplySingle;//回复单人集合
    DTModel *huifumsg;
    NSMutableArray *addata;
    int  zkindex;
    UIView *adView;
}
- (void)viewDidLoad {
    
    
    [super viewDidLoad];
    
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    [IQKeyboardManager sharedManager].enable = NO;
    self.table.tableHeaderView = self.adView;
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(scollTop:)
     name:@"scollTops"
     object:nil];
    
    
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(refdataDt:)
     name:@"refDataDT"
     object:nil];
    _table.bdelegate = self;
    data = [NSMutableArray array];
    CGRect c = _table.frame;
    c.size.height = c.size.height-[AppDelegate shareDelegate]._tableBarController.tabBar.frame.size.height;
    _table.frame = c;
    
    _inputView = [[UIView alloc]initWithFrame:CGRectMake(0, SCRE_HEIGHT-52, SCRE_WIDTH, 52)];
    _inputView.backgroundColor = UIColorFromRGB(0xf3f3f3);
    _bqBtn = [[UIButton alloc]initWithFrame:CGRectMake(12, 12, 30, 26)];
    [_bqBtn setImage:[UIImage imageNamed:@"bq"] forState:UIControlStateNormal];
    [_bqBtn addTarget:self action:@selector(bqAction:) forControlEvents:UIControlEventTouchUpInside];
    [_inputView addSubview:_bqBtn];
    _inputView.layer.cornerRadius = 4;
    _hfText = [[UITextView alloc]initWithFrame:CGRectMake(50, 8, SCRE_WIDTH-(60+55), 35)];
    _hfText.delegate = self;
    [_inputView addSubview:_hfText];
    _senderBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCRE_WIDTH - 55, 8, 45, 35)];
    [_senderBtn setTitle:@"发送" forState:UIControlStateNormal];
    [_senderBtn setBackgroundColor:UIColorFromRGB(0x263656)];
    _senderBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_senderBtn addTarget:self action:@selector(addHfAction:) forControlEvents:UIControlEventTouchUpInside];
    [_inputView addSubview:_senderBtn];
    _senderBtn.layer.cornerRadius = 4;
    _inputView.hidden = YES;
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:_inputView];
    
    NSMutableDictionary *dic = [UserDefaults readUserDefaultObjectValueForKey:@"userLocation"];
    [dic setObject:[NSNumber numberWithInt:1] forKey:@"page"];
    if (![AppDelegate shareDelegate].isdeleteAd) {
        
        [[BusinessService shareInstance]dtaiguangg:dic success:^(id result) {
            NSMutableArray *qry = result;
            NSMutableArray *datas = [[NSMutableArray alloc]init];
            for (int i=0 ; i<qry.count; i++) {
                FJModel *msg = [qry objectAtIndex:i];
                [datas addObject:msg.img];
            }
            addata = qry;
            //网络加载 --- 创建带标题的图片轮播器
            SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCRE_WIDTH ,_adView.frame.size.height) imageURLStringsGroup:datas]; // 模拟网络延时情景
            cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
            cycleScrollView2.delegate = self;
            cycleScrollView2.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
            cycleScrollView2.placeholderImage = [UIImage imageNamed:@"placeholder"];
            [_adView addSubview:cycleScrollView2];
            
            UIButton *imgbtn = [[UIButton alloc]initWithFrame:CGRectMake(SCRE_WIDTH - 40, (64/2-15/2), 15, 15)];
            [imgbtn setImage:[UIImage imageNamed:@"delete_d.png"] forState:UIControlStateNormal];
            [_adView addSubview:imgbtn];
            
            UIButton  *delete = [[UIButton alloc]initWithFrame:CGRectMake(SCRE_WIDTH - 40, 64+(64/2-20), 20, 40)];
            [delete addTarget:self action:@selector(deleteAD:) forControlEvents:UIControlEventTouchUpInside];
            [[[[UIApplication sharedApplication] windows] firstObject] addSubview:delete];
        } failure:^(id result) {
            [SVProgressHUD showErrorWithStatus:result];
        }];
    }else{
        int viewh = _adView.frame.size.height;
        [_adView removeFromSuperview];
        //设置动画的名字
        [UIView beginAnimations: @"Animation" context: nil];
        //设置动画的开始移动位置
        [UIView setAnimationBeginsFromCurrentState: YES];
        //设置动画的间隔时间
        [UIView setAnimationDuration: 0.20];
        //设置视图移动的位移
        CGRect re = _table.frame;
        re.origin.y = 0;
        re.size.height = re.size.height+viewh;
        _table.frame = re;
        //设置动画结束
        [UIView commitAnimations];
    }
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
-(void)scollTop:(NSNotification *)not{
    if (data.count!=0) {
        [_table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}
-(void)refdataDt:(NSNotification *)btn{
    //    [_table Refresh];
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)indexs
{
    FJModel *model = [addata objectAtIndex:indexs];
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"toadview" object:model.url];
    
    
}
-(void)initData:(int)index{
    _table.backgroundColor = colorBG;
    NSMutableDictionary *dic = [UserDefaults readUserDefaultObjectValueForKey:@"userLocation"];
    [dic setObject:[NSNumber numberWithInt:index] forKey:@"page"];
    [[BusinessService shareInstance]getdynamic_nearby:dic success:^(id result) {
        data = [_table result:result olddata:data index:index];
        if (notlabel) {
            [notlabel removeFromSuperview];
        }
        notlabel = (UILabel *)[_table notData];
        if (data.count == 0) {
            [self.view addSubview:notlabel];
        }
        [_table reloadData];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return data.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    //    cell.backgroundColor = colorBG;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    DTModel *model = [data objectAtIndex:indexPath.section];
    UIView *bgview= [[UIView alloc]initWithFrame:CGRectMake(0, 20, SCRE_WIDTH, 300)];
    //基础UI
    int b = [_table Basics:cell dtmodel:model bgview:bgview];
    //个人头像按钮
    UIButton *headbtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 10, 45, 45)];
    headbtn.tag = indexPath.section;
    [headbtn addTarget:self action:@selector(toIndividualAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:headbtn];
    int file = 0;
    //附件
    if (model.attachment.count != 0) {
        file = [_table Attachment:cell dtmodel:model bgview:bgview];
        NSMutableDictionary *dic = [model.attachment lastObject];
        NSString *url = [dic objectForKey:@"path"];
        url = [url substringFromIndex:url.length-3];
        //附件按钮
        BaseButton *headbtn = [[BaseButton alloc]initWithFrame:CGRectMake(0, 45, SCRE_WIDTH, file)];
        headbtn.tag = indexPath.section;
        if ([url isEqualToString:@"mp4"]) {
            if (!model.iskuaipai) {
                [headbtn setImage:[UIImage imageNamed:@"图标---视频播放"] forState:UIControlStateNormal];
            }

        }
        [headbtn addTarget:self action:@selector(imgTouchAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgview addSubview:headbtn];
    }
    //    //内容
    MLEmojiLabel * _emojiLabel = [MLEmojiLabel new];
    _emojiLabel.numberOfLines = 0;
    _emojiLabel.font = [UIFont systemFontOfSize:15.0f];
    _emojiLabel.backgroundColor = [UIColor clearColor];
    _emojiLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _emojiLabel.textColor = [UIColor blackColor];
    
    _emojiLabel.textInsets = UIEdgeInsetsMake(0, 5, 0, 5);
    _emojiLabel.isNeedAtAndPoundSign = YES;
    _emojiLabel.disableEmoji = NO;
    _emojiLabel.disableThreeCommon = NO;
    _emojiLabel.delegate = self;
    _emojiLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentCenter;
    _emojiLabel.customEmojiRegex = @"\\[[emoji_[0-9]{1,3}]+\\]";
    _emojiLabel.customEmojiPlistName = @"expressionImage_custom.plist";
    [_emojiLabel setText:[NSString stringWithFormat:@"%@",model.title]];
    [bgview addSubview:_emojiLabel];
    CGRect g = _emojiLabel.frame;
    g.size.height = ([_emojiLabel preferredSizeWithMaxWidth:bgview.frame.size.width].height+10.0f*2);
    g.origin.y =  b+file;
    g.size.width = SCRE_WIDTH-10;
    g.origin.x = 0;
    _emojiLabel.frame = g;
    
    //头像高度+内容+图片高度
    int bottom = b+file+10 +g.size.height;
    
    if ([_emojiLabel.text trim].length==0) {
        bottom = b+file+10;
    }
    if(model.linkurl.length != 0){
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(15, bottom, bgview.frame.size.width - 30, 200)];
        view.layer.borderWidth = 0.5;
        view.layer.borderColor = colorBG.CGColor;
        [bgview addSubview:view];
        BaseButton  *btn = [[BaseButton alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        [btn addTarget:self action:@selector(toweb:) forControlEvents:UIControlEventTouchUpInside];
//        NSMutableDictionary *dic = [ValidateHelper GetHtmlImgOrTitle:model.linkurl];
//        if (!dic) {
//            UITextView *titletext = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width , 90)];
//            titletext.text = @"该链接无法识别";
//            titletext.userInteractionEnabled = NO;
//            [view addSubview:titletext];
//        }else{
            UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 70, 70)];
        img.backgroundColor = UIColorRed;
             [img sd_setImageWithURLs:[NSURL URLWithString:model.linkurl_img] placeholderImage:[UIImage imageNamed:@"notimgs"]];
        img.contentMode = UIViewContentModeScaleAspectFill;
            [view addSubview:img];
            
            UITextView *titletext = [[UITextView alloc]initWithFrame:CGRectMake(90, 5, view.frame.size.width - 90, 90)];
            titletext.text = model.linkurl_title;
            titletext.userInteractionEnabled = NO;
            [view addSubview:titletext];
            btn.name = model.linkurl;
            [view addSubview:btn];
//        }
        bottom = bottom + 80;
        BaseButton *dizhi = [[BaseButton alloc]initWithFrame:CGRectMake(25, bottom+20, (SCRE_WIDTH)-90, 30)];
        dizhi.titleLabel.font = [UIFont systemFontOfSize:14];
        [dizhi setTitle:model.cityname forState:UIControlStateNormal];
        dizhi.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [dizhi setTitleColor:colorGrey forState:UIControlStateNormal];
        dizhi.model = model;
        [dizhi addTarget:self action:@selector(tomap:) forControlEvents:UIControlEventTouchUpInside];
        [bgview addSubview:dizhi];
        
        UIImageView *zidiimg = [[UIImageView alloc]initWithFrame:CGRectMake(10,dizhi.frame.origin.y+10, 9, 12.5)];
        zidiimg.image = [UIImage imageNamed:@"图标---位置"];
        [bgview addSubview:zidiimg];
    }else{
        BaseButton *dizhi = [[BaseButton alloc]initWithFrame:CGRectMake(25, bottom, (SCRE_WIDTH)-90, 30)];
        dizhi.titleLabel.font = [UIFont systemFontOfSize:14];
        [dizhi setTitle:model.cityname forState:UIControlStateNormal];
        dizhi.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [dizhi setTitleColor:colorGrey forState:UIControlStateNormal];
        dizhi.model = model;
        [dizhi addTarget:self action:@selector(tomap:) forControlEvents:UIControlEventTouchUpInside];
        [bgview addSubview:dizhi];
        
        UIImageView *zidiimg = [[UIImageView alloc]initWithFrame:CGRectMake(10,dizhi.frame.origin.y+10, 9, 12.5)];
        zidiimg.image = [UIImage imageNamed:@"图标---位置"];
        [bgview addSubview:zidiimg];
    }

    
    
    
    
    
  
    
    bottom = bottom + 43;

    
    UIButton *sharebtn = [[UIButton alloc]initWithFrame:CGRectMake(85, bottom, 40, 40)];
    [sharebtn setImage:[UIImage imageNamed:@"图标---转发"] forState:UIControlStateNormal];
    //    [sharebtn setTitle:model.sharecount forState:UIControlStateNormal];
    [sharebtn setTitleColor:colorGrey forState:UIControlStateNormal];
    [sharebtn addTarget:self action:@selector(fenxiang:) forControlEvents:UIControlEventTouchUpInside];
    sharebtn.tag = indexPath.section;
    sharebtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [bgview addSubview:sharebtn];
    
    UIButton *zanbtn = [[UIButton alloc]initWithFrame:CGRectMake(5, bottom, 40, 40)];
    zanbtn.tag = indexPath.section;
    if ([model.iszan intValue] == 1) {
        [zanbtn setImage:[UIImage imageNamed:@"图标---赞"] forState:UIControlStateNormal];
    }else{
        [zanbtn setImage:[UIImage imageNamed:@"图标---喜欢"] forState:UIControlStateNormal];
    }
    [zanbtn addTarget:self action:@selector(praiseAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [bgview addSubview:zanbtn];
    
    BaseButton *plbtn = [[BaseButton alloc]initWithFrame:CGRectMake(45, bottom, 40, 40)];
    [plbtn setImage:[UIImage imageNamed:@"图标---评论"] forState:UIControlStateNormal];
    [plbtn setTitleColor:colorGrey forState:UIControlStateNormal];
    plbtn.titleLabel.font = [UIFont systemFontOfSize:12];
    plbtn.tag = indexPath.section;
    //    [plbtn setTitle:model.commentcount forState:UIControlStateNormal];
    [plbtn addTarget:self action:@selector(toReplyAction:) forControlEvents:UIControlEventTouchUpInside];
    [bgview addSubview:plbtn];
    
    
    
    
    
    UILabel *distance = [[UILabel alloc]initWithFrame:CGRectMake((SCRE_WIDTH)-90, bottom,80, 30)];
    distance.text = [ValidateHelper DistanceFormat:model.distance];
    distance.font = [UIFont systemFontOfSize:14];
    distance.textColor = colorGrey;
    distance.textAlignment = NSTextAlignmentRight;
    [bgview addSubview:distance];
    
    //按钮分割线
    UILabel *ine = [[UILabel alloc]initWithFrame:CGRectMake(0, bottom + 40,SCRE_WIDTH,0.5)];
    ine.backgroundColor = colorBG;
    [bgview addSubview:ine];
    
    UILabel *zanlable = [[UILabel alloc]initWithFrame:CGRectMake(15, bottom + 40, SCRE_WIDTH-20, 30)];
    zanlable.text = [NSString stringWithFormat:@"❤︎%@次赞",model.zancount];
    zanlable.font = [UIFont systemFontOfSize:13];
    [bgview addSubview:zanlable];
    
    // 留言
    int ly = zanlable.frame.size.height + zanlable.frame.origin.y;
    int y = ly;
    int liuh=0;
    
    //    if (zkindex==indexPath.section+1) {
    if (model.commentlist.count!=0) {
        liuh=0;
        y = ly;
        for (int i = 0; i<model.commentlist.count; i++) {
            NSMutableDictionary *dic = [model.commentlist objectAtIndex:i];
            if (i>=3) {
                BaseButton *btn = [[BaseButton alloc]initWithFrame:CGRectMake(10, y-10, 60, 30)];
                [btn addTarget:self action:@selector(toxiangq:) forControlEvents:UIControlEventTouchUpInside];
                [btn setTitle:@"查看更多" forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:12];
                [bgview addSubview:btn];
                btn.model = model;
                y = y + 30;
                break;
            }else{
                int x =0;
                NSString *rname = [dic objectForKey:@"reply_nickname"];
                NSString *nickname = [dic objectForKey:@"nickname"];
                
                
                //                UIImageView *head = [[UIImageView alloc]initWithFrame:CGRectMake(10+x, y, 35, 35)];
                //                [head sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"headsmall"]]
                //                        placeholderImage:[UIImage imageNamed:@"mrtx"]];
                //                head.layer.cornerRadius = 35/2;
                //                head.clipsToBounds = YES;
                CGSize n = [ValidateHelper sizeOfText:![rname isEqualToString:nickname]?[NSString stringWithFormat:@"%@回复%@:",[dic objectForKey:@"nickname"],[dic objectForKey:@"reply_nickname"]]:[NSString stringWithFormat:@"%@:",[dic objectForKey:@"nickname"]]  theFont:[UIFont systemFontOfSize:13]];
                
                //                [bgview addSubview:head];
                BaseButton *btn = [[BaseButton alloc]initWithFrame:CGRectMake(10, y,n.width+10, 30)];
                [btn addTarget:self action:@selector(SingleReplyActino:) forControlEvents:UIControlEventTouchUpInside];
                btn.tag = indexPath.section;
                btn.index = i;
                btn.titleLabel.textAlignment = NSTextAlignmentRight;
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                NSString *titlename =![rname isEqualToString:nickname]?[NSString stringWithFormat:@"%@回复%@:",[dic objectForKey:@"nickname"],[dic objectForKey:@"reply_nickname"]]:[NSString stringWithFormat:@"%@:",[dic objectForKey:@"nickname"]];
                //                [btn setTitle:titlename forState:UIControlStateNormal];
                
                btn.titleLabel.font = [UIFont systemFontOfSize:14];
                [bgview addSubview:btn];
                
                
                MLEmojiLabel * _emojiLabel = [MLEmojiLabel new];
                _emojiLabel.numberOfLines = 0;
                _emojiLabel.font = [UIFont systemFontOfSize:14.0f];
                _emojiLabel.backgroundColor = [UIColor clearColor];
                _emojiLabel.lineBreakMode = NSLineBreakByWordWrapping;
                _emojiLabel.textColor = [UIColor blackColor];
                
                _emojiLabel.textInsets = UIEdgeInsetsMake(0, 0, 0, 0);
                _emojiLabel.isNeedAtAndPoundSign = YES;
                _emojiLabel.disableEmoji = NO;
                _emojiLabel.disableThreeCommon = YES;
                _emojiLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentCenter;
                _emojiLabel.customEmojiRegex = @"\\[[emoji_[0-9]{1,3}]+\\]";
                _emojiLabel.customEmojiPlistName = @"expressionImage_custom.plist";
                [_emojiLabel setText:[NSString stringWithFormat:@"%@%@",titlename,[dic objectForKey:@"content"]]];
                int  h =   SCRE_WIDTH - 20;
                
                CGSize size = [_emojiLabel preferredSizeWithMaxWidth:h];
                
                CGRect g = _emojiLabel.frame;
                g.size.height = ([_emojiLabel preferredSizeWithMaxWidth:size.width].height+10.0f);
                g.origin.y = btn.frame.origin.y - 3;
                g.size.width = SCRE_WIDTH - 20;
                g.origin.x = 15;
                _emojiLabel.frame = g;
                
                
                [bgview addSubview:_emojiLabel];
                y = y + _emojiLabel.frame.size.height;
            }
        }
        liuh =  y - ly;
    }
    //    }
    CGSize s =[ValidateHelper sizeOfText:distance.text theFont:[UIFont systemFontOfSize:14]];
    CGRect di = distance.frame;
    di.size.width = s.width +10;
    di.origin.x = (SCRE_WIDTH) - s.width -20;
    distance.frame = di;
    
    CGRect bg = bgview.frame;
    bg.size.height = zanlable.frame.size.height+zanlable.frame.origin.y + liuh;
    bgview.frame = bg;
    
    CGRect cl =  cell.frame;
    cl.size.height = bg.size.height+30;
    cell.frame = cl;
    
    if ([model.iskuaipai isEqualToString:@"1"]) {
        UIView *bgviews = [[UIView alloc]initWithFrame:CGRectMake(SCRE_WIDTH - 70, 55, 60, 20)];
        bgviews.backgroundColor = UIColorMakeWithRGBA(0, 0, 0, 0.3);
        bgviews.layer.masksToBounds = YES;
        bgviews.layer.borderWidth = 1;
        bgviews.layer.borderColor = UIColorWhite.CGColor;
        bgviews.layer.cornerRadius = 10;
        
        
        [bgview addSubview:bgviews];
        
        
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 20)];
        lable.text = [model.isimg isEqualToString:@"1"] ? @"快照" : @"现场";
        lable.layer.cornerRadius = 10;
        lable.clipsToBounds = YES;
        
        lable.textAlignment = NSTextAlignmentCenter;
        lable.textColor = [UIColor whiteColor];
        
        lable.font = [UIFont systemFontOfSize:15];
        [bgviews addSubview:lable];
    }
    return cell;
}
#pragma mark 链接跳转
-(void)toweb:(BaseButton *)btn{
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"toadview" object:btn.name];
}
-(void)tomap:(BaseButton *)btn{
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"tomap" object:btn.model];
    
}
-(void)toxiangq:(BaseButton *)btn{
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"toDetails" object:btn.model];
}
#pragma  mark 分享
-(void)fenxiang:(BaseButton *)btn{
    UIActionSheet * editActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    editActionSheet.tag = btn.tag;
    [editActionSheet addButtonWithTitle:@"微博"];
    [editActionSheet addButtonWithTitle:@"微信好友"];
    [editActionSheet addButtonWithTitle:@"朋友圈"];
    [editActionSheet addButtonWithTitle:@"QQ空间"];
    [editActionSheet addButtonWithTitle:@"QQ"];
    [editActionSheet addButtonWithTitle:@"取消"];
    editActionSheet.cancelButtonIndex = editActionSheet.numberOfButtons - 1;
    [editActionSheet showFromTabBar:self.tabBarController.tabBar];
    editActionSheet.delegate = self;
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex + 1 >= actionSheet.numberOfButtons ) {
        return;
    }
    DTModel *model = [data objectAtIndex:actionSheet.tag];
    
    NSString *snsName;
    if (buttonIndex == 0) {
        snsName = @"sina";
    }else if (buttonIndex == 1){
        snsName = @"wxsession";
    }else if (buttonIndex == 2){
        snsName = @"wxtimeline";
    }else if (buttonIndex == 3){
        snsName = @"qzone";
    }else if (buttonIndex == 4){
        snsName = @"qq";
    }
    
    UMSocialUrlResource *res;
    NSMutableDictionary *dic = [model.attachment lastObject];
    NSString *url = [dic objectForKey:@"path"];
    if (![ValidateHelper isHttpHead:url]) {
        url = [NSString stringWithFormat:@"%@%@",img_Url,url];
    }
    if ([url isEqualToString:@"mp4"]) {
        res = [[UMSocialUrlResource alloc]initWithSnsResourceType:UMSocialUrlResourceTypeVideo url:url];
    }else{
        res = [[UMSocialUrlResource alloc]initWithSnsResourceType:UMSocialUrlResourceTypeImage url:url];
    }
    UIImage *shareImage = [UIImage imageNamed:@"icon"];
    [[AppDelegate shareDelegate]refuser:model.uid success:^(id as) {
        LoginResponseModel *user = as;
        [[UMSocialDataService defaultDataService] postSNSWithTypes:@[snsName] content:[NSString stringWithFormat:@"一米社交的[%@]发布的动态",user.nickname] image:nil location:nil urlResource:res presentedController:self completion:^(UMSocialResponseEntity * response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"成功" message:@"分享成功" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil];
                [alertView show];
                NSMutableDictionary *dic= [[NSMutableDictionary alloc]init];
                [dic setObject:@"1" forKey:@"type"];
                [dic setObject:model.id forKey:@"content"];
                [dic setObject:@"1" forKey:@"isopen"];
                
                [dic setObject:@"0" forKey:@"isweibo"];
                [dic setObject:@"0" forKey:@"isweixin"];
                [dic setObject:@"0" forKey:@"isweixinquan"];
                [dic setObject:@"0" forKey:@"isqqzone"];
                [dic setObject:@"0" forKey:@"isqq"];
                
                if (buttonIndex == 0) {
                    [dic setObject:@"1" forKey:@"isweibo"];
                }else if (buttonIndex == 1){
                    [dic setObject:@"1" forKey:@"isweixin"];
                }else if (buttonIndex == 2){
                    [dic setObject:@"1" forKey:@"isweixinquan"];
                }else if (buttonIndex == 3){
                    [dic setObject:@"1" forKey:@"isqqzone"];
                }else if (buttonIndex == 4){
                    [dic setObject:@"1" forKey:@"isqq"];
                }
                [dic setObject:@"1" forKey:@"isopen"];
                [[BusinessService shareInstance]sharerecord:dic success:^(id result) {
                    
                } failure:^(id result) {
                    
                }];
            } else if(response.responseCode != UMSResponseCodeCancel) {
                UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"失败" message:@"分享失败" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil];
                [alertView show];
            }
        }];
        
    }];
    
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initdata:) name:@"initdataren" object:nil];
    DTModel *msg = [data objectAtIndex:indexPath.section];
    
    if ([msg.iskuaipai isEqualToString:@"1"]) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        DTModel *model = [data objectAtIndex:indexPath.section];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        [dic setObject:model.id forKey:@"id"];
        [SVProgressHUD showWithStatus:@"加载中..."];
        [[BusinessService shareInstance]kuaipai_detail:dic success:^(id result) {
            user = result;
            [[BusinessService shareInstance]enterGroup:dic success:^(id result) {
                [SVProgressHUD dismiss];
                models = result;
                UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"FJ"
                                                                             bundle:[NSBundle mainBundle]];
                KPDViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"KPDViewController"];
                searchResultDetailController.model = models;
                searchResultDetailController.user = user;
                searchResultDetailController.ary = data;
                searchResultDetailController.notify = not;
                searchResultDetailController.index = indexPath.section;
                [self.nav pushViewController:searchResultDetailController animated:YES];
                
            } failure:^(id result) {
                [SVProgressHUD showErrorWithStatus:result];
            }];
        } failure:^(id result) {
            [SVProgressHUD showErrorWithStatus:result];
        }];

    }
    
    if (zkindex==(int)indexPath.section+1) {
        
        [[NSNotificationCenter defaultCenter ]postNotificationName:@"toDetails" object:msg];
        return;
    }
    zkindex = (int)indexPath.section+1;
    
    if(msg.commentlist.count!=0){
        [_table reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
    }else{
        
        [[NSNotificationCenter defaultCenter ]postNotificationName:@"toDetails" object:msg];
    }
    
}

-(void)initdata:(NSNotification *)sender{
    not = sender.object;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    DTModel *model = [data objectAtIndex:collectionView.tag];
    return  model.zanlist.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DTModel *model = [data objectAtIndex:collectionView.tag];
    NSMutableDictionary *dic = [model.zanlist objectAtIndex:indexPath.row];
    
    zanCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"zanCell" forIndexPath:indexPath];
    UIImageView *head = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 35, 35)];
    head.layer.cornerRadius = 35/2;
    head.clipsToBounds = YES;
    [head sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"headsmall"]]
            placeholderImage:[UIImage imageNamed:@"mrtx"]];
    [cell.contentView addSubview:head];
    
    UIImageView *bq = [[UIImageView alloc]initWithFrame:CGRectMake(35-18, 35-20, 18, 15)];
    bq.image = [UIImage imageNamed:[dic objectForKey:@"content"]];
    [head addSubview:bq];
    
    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 5, 0, 5);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size = CGSizeMake(32, 32);
    return size;
}
#pragma  mark URL 跳转
-(void)mlEmojiLabel:(MLEmojiLabel *)emojiLabel didSelectLink:(NSString *)link withType:(MLEmojiLabelLinkType)type{
}
-(void)toReplyAction:(BaseButton *)btn{
    huifumsg = [data objectAtIndex:btn.tag];
    _inputView.tag = btn.tag;
    _inputView.hidden = NO;
    _hfText.text = @"评论";
    [_hfText becomeFirstResponder];
};
#pragma mark 图片详情
-(void)imgTouchAction:(BaseButton *)sender{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initdata:) name:@"initdataren" object:nil];
    DTModel *msg = [data objectAtIndex:sender.tag];
    
    if ([msg.iskuaipai isEqualToString:@"1"]) {
        
//        DTModel *model = [data objectAtIndex:indexPath.section];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        [dic setObject:msg.id forKey:@"id"];
        [SVProgressHUD showWithStatus:@"加载中..."];
        [[BusinessService shareInstance]kuaipai_detail:dic success:^(id result) {
            user = result;
            [[BusinessService shareInstance]enterGroup:dic success:^(id result) {
                [SVProgressHUD dismiss];
                models = result;
                UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"FJ"
                                                                             bundle:[NSBundle mainBundle]];
                KPDViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"KPDViewController"];
                searchResultDetailController.model = models;
                searchResultDetailController.user = user;
                searchResultDetailController.ary = data;
                searchResultDetailController.notify = not;
                searchResultDetailController.index = sender.tag;
                [self.nav pushViewController:searchResultDetailController animated:YES];
                
            } failure:^(id result) {
                [SVProgressHUD showErrorWithStatus:result];
            }];
        } failure:^(id result) {
            [SVProgressHUD showErrorWithStatus:result];
        }];
        
        
    }else{
        NSString *url;
        NSMutableDictionary *dic = [msg.attachment lastObject];
        url = [dic objectForKey:@"path"];
        if (![ValidateHelper isHttpHead:url]) {
            url = [NSString stringWithFormat:@"%@%@",img_Url,url];
        }
        if ([dic objectForKey:@"path"]) {
            if([url rangeOfString:@"mp4"].location !=NSNotFound){//_roaldSearchText
                [[NSNotificationCenter defaultCenter ]postNotificationName:@"hPlay" object:url];
            }else{
                [[NSNotificationCenter defaultCenter ]postNotificationName:@"EnlargePicAction" object:msg];
            }}
    }

    
    
    
}
#pragma mark 单人回复
-(void)SingleReplyActino:(BaseButton *)btn{
    isReplySingle = 1;
    huifumsg = [data objectAtIndex:btn.tag];
    ReplySingle = [huifumsg.commentlist objectAtIndex:btn.index];
    if ([AppDelegate shareDelegate].user.uid == [ReplySingle objectForKey:@"uid"]) {
        [SVProgressHUD showErrorWithStatus:@"不能回复自己评论"];
        return;
    }
    _hfText.text = @"回复";
    _inputView.tag = btn.tag;
    _inputView.hidden = NO;
    [_hfText becomeFirstResponder];
}
#pragma mark 添加回复
- (IBAction)addHfAction:(UIButton *)sender {
    if([_hfText.text trim].length > 300){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"超过%d个字符",(int)[_hfText.text trim].length - 300] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    _inputView.hidden = YES;
    [self.view endEditing:YES];
    [inputView removeFromSuperview];
    [self up:NO];
    huifumsg = [data objectAtIndex:sender.tag];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[_hfText.textStorage getPlainString]  forKey:@"content"];
    if (isReplySingle == 0) {
        [dic setObject:huifumsg.id forKey:@"id"];
        [dic setObject:huifumsg.uid forKey:@"replyuid"];
    }else{
        [dic setObject:huifumsg.id forKey:@"id"];
        [dic setObject:[ReplySingle objectForKey:@"uid"] forKey:@"replyuid"];
    }
    [[BusinessService shareInstance]addreply:dic success:^(id result) {
        _hfText.text = nil;
        _table.refresh = YES;
        [_table  headerRereshing];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSUInteger proposedNewLength = textView.text.length - range.length + text.length;
    if ([textView.text isEqualToString:@"回复"]||[textView.text isEqualToString:@"评论"]) {
        textView.text = @"";
    }
    if(text.length==0){
        return YES;
    }
    if (proposedNewLength > 300)
        return NO;//限制长度
    return YES;
}
- (IBAction)bqAction:(UIButton *)sender {
    _inputView.hidden = NO;
    inputView.hidden = NO;
    [inputView removeFromSuperview];
    inputView = [[KYExpressionInputView alloc] init];
    inputView.frame = CGRectMake(0, SCRE_HEIGHT-inputView.frame.size.height+5, SCRE_WIDTH, inputView.frame.size.height);
    inputView.toolbarColor = [UIColor whiteColor];
    inputView.backgroundColor = [UIColor whiteColor];
    
    inputView.toolbar.hidden = YES;
    inputView.tag = 1994;
    [inputView setToolbarSendButtonHidden:YES animated:NO];
    [inputView addToolbarItemWithImage:nil title:nil items:[AppDelegate shareDelegate].emojiItems row:KYUIntegerOrientationMake(4, 5) column:KYUIntegerOrientationMake(8, 14) itemSize:KYSizeOrientationMake(CGSizeMake(36, 36), CGSizeMake(36, 36)) itemSpacing:KYFloatOrientationMake(6, 8)];
    inputView.delegate = self;
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:inputView];
    [self up:YES];
    [self.view endEditing:YES];
    [_hfText resignFirstResponder];
    isUp = YES;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isKindOfClass:[UITextView class]]) {
        return;
    }
    _inputView.hidden = YES;
    [self.view endEditing:YES];
    [inputView removeFromSuperview];
    [self up:NO];
}
- (void)inputView:(KYExpressionInputView *)inputView didSelectExpression:(id<KYExpressionData>)expression {
    if (inputView.tag == 1994) {//评论表情
        NSString *picName = [expression imageUrl];
        NSLog(@"%@",picName);
        //Create emoji attachment
        EmojiTextAttachment *emojiTextAttachment = [EmojiTextAttachment new];
        emojiTextAttachment.emojiTag =[NSString stringWithFormat:@"[%@]",picName];
        //Set tag and image
        emojiTextAttachment.image = [UIImage imageNamed:picName];
        emojiTextAttachment.emojiSize = 20;
        emojiTextAttachment.bql = -5;
        //Insert emoji image
        [_hfText.textStorage insertAttributedString:[NSAttributedString attributedStringWithAttachment:emojiTextAttachment]
                                            atIndex:_hfText.selectedRange.location];
        
        //Move selection location
        _hfText.selectedRange = NSMakeRange(_hfText.selectedRange.location + 1, _hfText.selectedRange.length);
        
    }else{//赞表情
        DTModel *msg = [data objectAtIndex:inputView.tag];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        if ([msg.iszan intValue]==0) {
            [dic setObject:@"1" forKey:@"type"];
        }else{
            [dic setObject:@"0" forKey:@"type"];
        }
        [dic setObject:msg.id forKey:@"id"];
        [dic setObject:@"emoji_52" forKey:@"content"];
        [[BusinessService shareInstance]praise:dic success:^(id result) {
            if ([msg.iszan intValue]==0) {
                msg.zancount = [NSString stringWithFormat:@"%d",[msg.zancount intValue]+1];
            }else{
                msg.zancount = [NSString stringWithFormat:@"%d",[msg.zancount intValue]-1];
            }
            if ([msg.iszan intValue]==0) {
                msg.iszan = @"1";
            }else{
                msg.iszan = @"0";
            }
            [data removeObjectAtIndex:inputView.tag];
            [data insertObject:msg atIndex:inputView.tag];
            [_table reloadData];
            [inputView removeFromSuperview];
            
        } failure:^(id result) {
            [SVProgressHUD showErrorWithStatus:result];
        }];
        
    }
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    [self registerForKeyboardNotifications];
    return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
//视图上移的方法
- (void)  up: (BOOL) up
{
    //  键盘退出的frame
    CGRect frame = inputView.frame;
    //键盘实时y
    CGFloat keyY = frame.origin.y;
    if (!up) {
        keyY = SCRE_HEIGHT;
    }
    //屏幕的高度
    CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
    //动画时间
    CGFloat keyDuration = 0.25;
    //执行动画
    [_inputView removeFromSuperview];
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:_inputView];
    
    [UIView animateWithDuration:keyDuration animations:^{
        _inputView.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
    }];
}

-(void)viewWillDisappear:(BOOL)animated
{
    _inputView.hidden = YES;
    [self.view endEditing:YES];
    [inputView removeFromSuperview];
    [self up:NO];
    _table.refresh = NO;
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(scollTop:)
     name:@"scollTops"
     object:nil];
    [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
    [IQKeyboardManager sharedManager].enable = YES;
    
}
- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShownHes:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)keyboardWasShownHes:(NSNotification*)noti{
    //改变window的背景颜色
    self.view.window.backgroundColor = _table.backgroundColor;
    //  键盘退出的frame
    CGRect frame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    //键盘实时y
    CGFloat keyY = frame.origin.y;
    if (inputView) {
        keyY = SCRE_HEIGHT ;
        isUp = NO;
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    if(isUp){
        keyY = SCRE_HEIGHT ;
        isUp = NO;
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    //屏幕的高度
    CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
    
    //动画时间
    CGFloat keyDuration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    //执行动画
    [UIView animateWithDuration:keyDuration animations:^{
        _inputView.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark 个人信息
- (IBAction)toIndividualAction:(UIButton *)sender {
    DTModel *model = [data objectAtIndex:sender.tag];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:model.uid forKey:@"fuid"];
    //    [SVProgressHUD showWithStatus:@"加载中..."];
    //    [[BusinessService shareInstance]userDetail:dic success:^(id result) {
    //        [SVProgressHUD dismiss];
    //    } failure:^(id result) {
    //    }];
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"FriendDetailsMainVC" object:model];
    
    
    
}

#pragma mark   赞
- (IBAction)praiseAction:(UIButton *)sender {
    //    inputView.hidden = NO;
    //    [inputView removeFromSuperview];
    //    inputView = [[KYExpressionInputView alloc] init];
    //    inputView.frame = CGRectMake(0, SCRE_HEIGHT-inputView.frame.size.height+5, SCRE_WIDTH, inputView.frame.size.height);
    //    inputView.toolbarColor = [UIColor whiteColor];
    //    inputView.backgroundColor = [UIColor whiteColor];
    //    inputView.tag = sender.tag;
    //    inputView.toolbar.hidden = YES;
    //    [inputView setToolbarSendButtonHidden:YES animated:NO];
    //    [inputView addToolbarItemWithImage:nil title:nil items:[AppDelegate shareDelegate].emojiItems row:KYUIntegerOrientationMake(4, 5) column:KYUIntegerOrientationMake(8, 14) itemSize:KYSizeOrientationMake(CGSizeMake(36, 36), CGSizeMake(36, 36)) itemSpacing:KYFloatOrientationMake(6, 8)];
    //    inputView.delegate = self;
    //    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:inputView];
    
    DTModel *msg = [data objectAtIndex:sender.tag];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    if ([msg.iszan intValue]==0) {
        [dic setObject:@"1" forKey:@"type"];
    }else{
        [dic setObject:@"0" forKey:@"type"];
    }
    [dic setObject:msg.id forKey:@"id"];
    [dic setObject:@"emoji_52" forKey:@"content"];
    [[BusinessService shareInstance]praise:dic success:^(id result) {
        if ([msg.iszan intValue]==0) {
            msg.zancount = [NSString stringWithFormat:@"%d",[msg.zancount intValue]+1];
        }else{
            msg.zancount = [NSString stringWithFormat:@"%d",[msg.zancount intValue]-1];
        }
        if ([msg.iszan intValue]==0) {
            msg.iszan = @"1";
        }else{
            msg.iszan = @"0";
        }
        [data removeObjectAtIndex:inputView.tag];
        [data insertObject:msg atIndex:inputView.tag];
        [_table reloadData];
        [inputView removeFromSuperview];
        
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
    
}
- (IBAction)deleteAD:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"deleteAD" object:nil];
    int viewh = _adView.frame.size.height;
    [_adView removeFromSuperview];
    [sender removeFromSuperview];
    //设置动画的名字
    [UIView beginAnimations: @"Animation" context: nil];
    //设置动画的开始移动位置
    [UIView setAnimationBeginsFromCurrentState: YES];
    //设置动画的间隔时间
    [UIView setAnimationDuration: 0.20];
    //设置视图移动的位移
    CGRect re = _table.frame;
    re.origin.y = 0;
    re.size.height = re.size.height+viewh;
    _table.frame = re;
    //设置动画结束
    [UIView commitAnimations];
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
